﻿
using Mes.Domain.BoundedContext;

namespace Mes.Application.DTO.Inputs.WorkOrders
{
    public class JobCommon
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;

        /// <summary>
        /// 作业描述
        /// </summary>
        public string? Job_Desc { get; set; }

        /// <summary>
        /// 所需完工日期/时间
        /// </summary>
        public DateTime? Req_Finish_Time_Local { get; set; } = DateTime.Now;

        /// <summary>
        /// 优先级
        /// </summary>
        public int Job_Priority { get; set; } = 50;

        /// <summary>
        /// 物料ID
        /// </summary>
        public int Item_Id { get; set; }

        ///// <summary>
        ///// 工单状态
        ///// </summary>
        //public int State_Cd { get; set; } = 1;

        /// <summary>
        /// 开工数量
        /// </summary>
        public double Qty_At_Start { get; set; }

        /// <summary>
        /// 所需产量
        /// </summary>
        public double Qty_Reqd { get; set; }

        /// <summary>
        /// 可调度ID
        /// </summary>
        public int Init_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 调度地ID
        /// </summary>
        public int Target_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 实际开工日期/时间
        /// </summary>
        public DateTime? Act_Start_Time_Local { get; set; } = DateTime.Now;

        /// <summary>
        /// 实际完工日期/时间
        /// </summary>
        public DateTime? Act_Finish_Time_Local { get; set; } = DateTime.Now;

        /// <summary>
        /// 备注
        /// </summary>
        public string? Notes { get; set; }
    }

    /// <summary>
    /// 添加作业入参
    /// </summary>
    public class AddingJobInput : JobCommon
    {
        /// <summary>
        /// 作业下的BOM清单入参
        /// </summary>
        public List<JobBOMInput> JobBOMs { get; set; }

        /// <summary>
        /// 作业下的工步组入参
        /// </summary>
        public List<JobStepGrpInput> JobStepGrps { get; set; }
    }

    public class JobBOMInput : JobBOMCommon { }

    /// <summary>
    /// BOM物料
    /// </summary>
    public class JobBOMCommon
    {
        /// <summary>
        /// 物料ID
        /// </summary>
        public int MaterialId { get; set; }

        /// <summary>
        /// 默认库存生产单元
        /// </summary>
        public int? DefaultStorageEntity { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public double Quantity { get; set; }

        /// <summary>
        /// 消耗量上限
        /// </summary>
        // public double? MaxConsumeQuantity { get; set; }

        /// <summary>
        /// 消耗量下限
        /// </summary>
        // public double? MinConsumeQuantity { get; set; }

        /// <summary>
        /// 开工量
        /// </summary>
        public double StartReqQuantity { get; set; }
    }

    public class JobStepGrpCommon
    {
        /// <summary>
        /// 工步组ID
        /// </summary>
        public int Step_Grp_Id { get; set; } = 0;

        /// <summary>
        /// 工步组描述
        /// </summary>
        public string Step_Grp_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 工步组序列
        /// </summary>
        public int Step_Grp_Seq { get; set; } = 0;
    }

    public class JobStepGrpInput : JobStepGrpCommon
    {
        /// <summary>
        /// 工步列表
        /// </summary>
        public IList<JobStepInput> JobSteps { get; set; } = new List<JobStepInput>();
    }

    public class JobStepInput
    {
        /// <summary>
        /// 工步编号
        /// </summary>
        public int Step_No { get; set; }

        /// <summary>
        /// 工步顺序
        /// </summary>
        public int Step_Seq { get; set; }

        /// <summary>
        /// 工步名称
        /// </summary>
        public string? Step_Name { get; set; } = null;

        /// <summary>
        /// 工步描述
        /// </summary>
        public string Step_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 工步BOM
        /// </summary>
        public IList<JobBomStepInput> JobBomSteps { get; set; } = new List<JobBomStepInput>();
    }

    public class JobBomStepInput
    {
        /// <summary>
        /// 工步数量
        /// </summary>
        public double Qty_Per_Parent_Item { get; set; }
    }

    /// <summary>
    /// 编辑作业入参
    /// </summary>
    public class UpdatingJobInput : AddingJobInput { }

    public class GettingJobInput
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;
    }

    public class DeletingJobInput
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;
    }

    public class GettingJobQueueInput
    {
        /// <summary>
        /// 查询关键字(作业名称和生产单元模糊查询)
        /// </summary>
        public string? KeyWord { get; set; }

        /// <summary>
        /// 分页参数
        /// </summary>
        public PagedInput PagedInput { get; set; } = new PagedInput();
    }
}
